package net.seehope.foodie.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

//是容器中的组件，而且是切面
@Component
@Aspect
public class TimeAspect {
	
	
	private static final Logger log = LoggerFactory.getLogger(TimeAspect.class);


	
	//設置切點
	@Pointcut("execution(* net.seehope..*.controller.IndexController.*(..))")
	public void timePointCut() {
		
	}
	
	//处理首页控制器
	@Around(value = "timePointCut()")
	public Object handleIndexController(ProceedingJoinPoint pjp) throws Throwable {
		long start = System.currentTimeMillis();
		log.info("TimeAspect start:"+ start);
		
		Object result = pjp.proceed();
		
		long end = System.currentTimeMillis();
		
		log.info("TimeAspect end:"+ end + "cost:" + (end-start));
		
		return result;
		
		
	}
	
}
